//
//  huopinVC.m
//  YaoHeAPP
//
//  Created by xyh on 16/3/21.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "huopinVC.h"
#import "Masonry.h"
#import "huopinTBVCell.h"
#import "TongYong.h"
#import "MyorderDataList.h"

#import "NSString+formatWithFloat.h"


#define bgVCcolor [UIColor colorWithRed:235.f/255.f green:235.f/255.f blue:244.f/255.f alpha:1]
#define Color153  [UIColor colorWithRed:80.f/255.f green:80.f/255.f blue:80.f/255.f alpha:1]
#define screenWidth self.view.frame.size.width
#define screenHeight self.view.frame.size.height

@interface huopinVC ()<UITableViewDataSource,UITableViewDelegate> {
    UILabel *buttomLabel;
}

@property(nonatomic, strong) UITableView *tableview;  //定义大表格

@end

@implementation huopinVC

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"huopinVC"];
    
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"huopinVC"];
    
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden=YES;
    
    self.view.backgroundColor=bgVCcolor;
    //加一个导航条
    UIView*navcBar=[[UIView alloc]init];
    navcBar.backgroundColor=[UIColor colorWithRed:90.f/255.f green:191.f/255.f blue:219.f/255.f alpha:1];
    [self.view addSubview:navcBar];
    [self.view bringSubviewToFront:navcBar];
    [navcBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);   make.left.offset(0);
        make.height.offset(kNavigationBarHeight);  make.right.offset(0);
    }];
    //导航条标题
    UILabel*titleLabel=[[UILabel alloc]init];
    titleLabel.text=@"货品清单";
    titleLabel.font=Font(17);
    titleLabel.textAlignment=NSTextAlignmentCenter;
    titleLabel.textColor=[UIColor whiteColor];
    [navcBar addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(25);
        make.left.offset(self.view.frame.size.width/2-70);
        make.width.offset(140);
        make.height.offset(30);
    }];
    
    //返回按钮
    UIButton*leftButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [leftButton setBackgroundImage:[UIImage imageNamed:@"return"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(backLogin) forControlEvents:UIControlEventTouchUpInside];
    [navcBar addSubview:leftButton];
    [leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(6);
        make.width.offset(24);
        make.height.offset(22);
        make.bottom.offset(-12);
    }];
    
    //创建表格
    _tableview=[[UITableView alloc]initWithFrame:CGRectMake(0,70, self.view.frame.size.width, self.view.frame.size.height-60)];
    _tableview.backgroundColor= [UIColor colorWithRed:230/255.0 green:232/255.0 blue:241/255.0  alpha:1];
    _tableview.delegate=self;
    _tableview.dataSource=self;
    _tableview.separatorStyle=NO;
    [self.view addSubview:_tableview];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if ([self.isXianhuo isEqualToString:@"现货列表"]) {
        
         return 2;
        
    }
        
        return self.OrderArray.count+1;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if ([self.isXianhuo isEqualToString:@"现货列表"]) {
        
        if (indexPath.row==1) {
            return 50;
        }
        
    } else {
    
      if (indexPath.row==self.OrderArray.count) {
        return 50;
       }
        
   }
    return 118;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if ([self.isXianhuo isEqualToString:@"现货列表"]) {
        
        if (indexPath.row==1) {
            
            static NSString *CellIdentifier1 = @"Cell";
            UITableViewCell*cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
            cell1.selectionStyle = UITableViewCellSelectionStyleNone;
            
            if (cell1 == nil) {
                cell1 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];
                cell1.selectionStyle = UITableViewCellSelectionStyleNone;
                cell1.backgroundColor=[UIColor colorWithRed:230/255.0 green:232/255.0 blue:241/255.0  alpha:1];
                
                UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 10, screenWidth, 40)];
                view.backgroundColor=[UIColor whiteColor];
                [cell1 addSubview:view];
                
                UILabel *shifuText=[[UILabel alloc]initWithFrame:CGRectMake(0, 10, screenWidth-10, 20)];
                //实付
                shifuText.font=[UIFont systemFontOfSize:12];
                shifuText.textAlignment=NSTextAlignmentRight;
                shifuText.textColor=[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0  alpha:1];
                [view addSubview:shifuText];
                
                NSDecimalNumber *zongmoneyDM = [[NSDecimalNumber alloc] initWithString:[NSString stringWithFormat:@"%@",self.zongmoney]];
                
                NSMutableAttributedString *tempString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"共1件货品,合计:%@元",[NSString notRounding:zongmoneyDM afterPoint:2]]];
                NSString *amountString = [NSString stringWithFormat:@"%@", [NSString notRounding:zongmoneyDM afterPoint:2]];
                [tempString addAttribute:NSForegroundColorAttributeName
                                   value:[UIColor redColor]
                                   range:NSMakeRange(1, 1)];
                [tempString addAttribute:NSForegroundColorAttributeName
                                   value:[UIColor redColor]
                                   range:NSMakeRange(9, amountString.length+1)];
                shifuText.attributedText = tempString;
                
                
            }
            
            return cell1;
           
        } else {
            
            gouwucartModel *gouwuMd=self.gouwuMDT;
            
            //指定cellIdentifier为自定义的cell
            static NSString *CellIdentifier = @"huopinTBVCell";
            //自定义cell类有图片
            huopinTBVCell*cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            if (cell == nil) {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"huopinTBVCell" owner:self options:nil] lastObject];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
            }
            //顶部字符串拼接
            NSString *toplable;
            if ([TongYong isBlankObjectAndStr:gouwuMd.SURFACE_CODE]) {
                toplable=[NSString stringWithFormat:@"%@ %@",gouwuMd.PARENT_NAME,gouwuMd.MATERIAL_CODE];
            } else {
                toplable=[NSString stringWithFormat:@"%@ %@/%@",gouwuMd.PARENT_NAME,gouwuMd.MATERIAL_CODE,gouwuMd.SURFACE_CODE];
                
            }
            cell.topLabel.text=toplable;
            
            //特惠图标
            NSInteger ispre=[gouwuMd.SALES_PROMOTION integerValue];
            if (ispre==1) {
                cell.topTehuiImage.hidden=NO;
                cell.topTehuiImage.image=[UIImage imageNamed:@"ic_preferential"];
            }else{
                cell.topTehuiImage.hidden=YES;
            }

            NSString *guige=gouwuMd.SPEC_CODE;
            
            //参厚
            NSString *canhou;
            if ([TongYong isBlankObjectAndStr:gouwuMd.REFERENCE_THICK ]) {
                canhou=@"";
            } else {
                canhou=[NSString stringWithFormat:@"(%@)",gouwuMd.REFERENCE_THICK];
            }
            
            //边部
            NSString *bianbu;
            if ([TongYong isBlankObjectAndStr:gouwuMd.EDGE_NAME ]) {
                bianbu=@"";
            } else {
                
                bianbu=[NSString stringWithFormat:@"/%@",gouwuMd.EDGE_NAME];
                
            }
            
            //等级
            NSString *dengji;
            if ([TongYong isBlankObjectAndStr:gouwuMd.LEVEL_NAME ]) {
                
                dengji=@"";
                
            } else {
                
                dengji=[NSString stringWithFormat:@"/%@",gouwuMd.LEVEL_NAME];
                
            }
            
            
            //包装
            NSString *baozhuang;
            if ([TongYong isBlankObjectAndStr:gouwuMd.PACKAGE_TYPE ]) {
                
                baozhuang=@"";
                
            } else {
                //包装类型//(30,"裸包"),(10,"简包"),(20,"精包"),(0,"正常包装")
                NSInteger typ=gouwuMd.PACKAGE_TYPE.integerValue;
                if (typ==30) {
                    baozhuang=[NSString stringWithFormat:@"/裸包"];
                } else if (typ==20){
                    baozhuang=[NSString stringWithFormat:@"/精包"];
                } else if (typ==10){
                    baozhuang=[NSString stringWithFormat:@"/简包"];
                } else {
                    
                    baozhuang=[NSString stringWithFormat:@"正常包装"];
                }
            }
            
            
            //形状
            NSString *xinzhuang;
            if ([TongYong isBlankObjectAndStr:gouwuMd.SHAPE ]) {
                
                xinzhuang=@"";
                
            } else {
                
                xinzhuang=[NSString stringWithFormat:@"/%@",gouwuMd.SHAPE];
                
            }
            
            //品名
            NSString *pingming;
            if ([TongYong isBlankObjectAndStr:gouwuMd.CATEGORY_NAME ]) {
                
                pingming=@"";
                
            } else {
                
                pingming=[NSString stringWithFormat:@"%@",gouwuMd.CATEGORY_NAME];
                
            }
            
            //单位类型
            NSInteger unitpric=gouwuMd.PRICE_UNIT.integerValue;

            //并且计算出金额
            //计算金额
            //单位类型
            NSString *QUANTITY=[NSString stringWithFormat:@"%@",gouwuMd.QUANTITY];
            NSString *weight=[NSString stringWithFormat:@"%@",gouwuMd.USEABLE_WEIGHT];
            NSString *sale_price=[NSString stringWithFormat:@"%@",gouwuMd.DISCOUNT_PRICE];
            
            NSDecimalNumber *quantityDM = [[NSDecimalNumber alloc] initWithString:QUANTITY];//个数
            NSDecimalNumber *weightDM = [[NSDecimalNumber alloc] initWithString:weight];//单个重量
            
            NSDecimalNumber *zongweightDM=[[NSDecimalNumber alloc]initWithString:@"0"];
            
            NSString *weightName;
            if (unitpric==10) {
                //元每吨
                NSDecimalNumber *qian = [[NSDecimalNumber alloc] initWithString:@"1000"];
                zongweightDM = [quantityDM decimalNumberByMultiplyingBy:weightDM];
                zongweightDM=[zongweightDM decimalNumberByDividingBy:qian];
                weightName=[NSString stringWithFormat:@"%@吨",[NSString notRounding:zongweightDM afterPoint:3]];
            } else if (unitpric==20||unitpric==40) {
                //支或张
                zongweightDM=quantityDM;
                weightName=[NSString stringWithFormat:@"%@",[NSString notRounding:zongweightDM afterPoint:0]];
            } else {
                //千克
                zongweightDM = [quantityDM decimalNumberByMultiplyingBy:weightDM];
                weightName=[NSString stringWithFormat:@"%@千克",[NSString notRounding:zongweightDM afterPoint:3]];
                
            }
            
            NSDecimalNumber *sale_priceDM = [[NSDecimalNumber alloc] initWithString:sale_price];
            NSDecimalNumber *everyON=[[NSDecimalNumber alloc]init];
            everyON = [sale_priceDM decimalNumberByMultiplyingBy:zongweightDM];
            
            
            cell.Moneylabel.text=[NSString stringWithFormat:@"￥%@元",[NSString notRounding:everyON afterPoint:2]];
            
            if (unitpric==20||unitpric==40) {
                
                zongweightDM = [quantityDM decimalNumberByMultiplyingBy:weightDM];
                weightName=[NSString stringWithFormat:@"%@千克",[NSString notRounding:zongweightDM afterPoint:3]];
            }
            
            NSString *bigTEXT;
            if ([gouwuMd.CATEGORY_NAME isEqualToString:@"板"]||[gouwuMd.CATEGORY_NAME isEqualToString:@"卷"]||[gouwuMd.CATEGORY_NAME isEqualToString:@"带"]) {
                //		板卷   规格(参厚)/边部/等级/包装
                
                bigTEXT=[NSString stringWithFormat:@"%@%@%@%@%@ %@",guige,canhou,bianbu,dengji,baozhuang,weightName];
                
                
            } else {
                
                bigTEXT=[NSString stringWithFormat:@"%@%@%@%@%@%@ %@",pingming,guige,xinzhuang,bianbu,dengji,baozhuang,weightName];
            }
            
            cell.bigLabel.text=bigTEXT;
            
            
            //仓库  生产商
            NSString *ck;
            if ([TongYong isBlankObjectAndStr:gouwuMd.HOUSE_NAME ]) {
                
                ck=@"";
                
            } else {
                
                ck=[NSString stringWithFormat:@"%@",gouwuMd.HOUSE_NAME];
                
            }
            
            NSString *scs;
            if ([TongYong isBlankObjectAndStr:gouwuMd.MANUFACTURER_NAME ]) {
                
                scs=@"";
                
            } else {
                
                scs=[NSString stringWithFormat:@"%@",gouwuMd.MANUFACTURER_NAME];
                
            }
            
            cell.dizhiandcangku.text=[NSString stringWithFormat:@"%@     %@",ck,scs];
            
            NSString *shulang=[NSString stringWithFormat:@"数量:x%@",gouwuMd.QUANTITY];
            cell.Numlabel.text=shulang;
            
            return cell;

    
        
        }
        
    } else {
    
    
    if (indexPath.row==self.OrderArray.count) {
        static NSString *CellIdentifier1 = @"Cell";
        UITableViewCell*cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
        cell1.selectionStyle = UITableViewCellSelectionStyleNone;

        if (cell1 == nil) {
            cell1 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];
            cell1.selectionStyle = UITableViewCellSelectionStyleNone;
            cell1.backgroundColor=[UIColor colorWithRed:230/255.0 green:232/255.0 blue:241/255.0  alpha:1];
            
            UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 10, screenWidth, 40)];
            view.backgroundColor=[UIColor whiteColor];
            [cell1 addSubview:view];
            
            UILabel *shifuText=[[UILabel alloc]initWithFrame:CGRectMake(0, 10, screenWidth-10, 20)];
            //实付
            shifuText.font=[UIFont systemFontOfSize:12];
            shifuText.textAlignment=NSTextAlignmentRight;
            shifuText.textColor=[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0  alpha:1];
            [view addSubview:shifuText];
            
            
            NSDecimalNumber *zongmoneyDM = [[NSDecimalNumber alloc] initWithString:[NSString stringWithFormat:@"%@",self.zongmoney]];
            
            NSMutableAttributedString *tempString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"共%lu件货品,合计:%@元",(unsigned long)self.OrderArray.count,[NSString notRounding:zongmoneyDM afterPoint:2]]];
            NSString *priceString = [NSString stringWithFormat:@"%lu", (unsigned long)self.OrderArray.count];
            NSString *amountString = [NSString stringWithFormat:@"%@", [NSString notRounding:zongmoneyDM afterPoint:2]];
            [tempString addAttribute:NSForegroundColorAttributeName
                               value:[UIColor redColor]
                               range:NSMakeRange(1, priceString.length)];
            [tempString addAttribute:NSForegroundColorAttributeName
                               value:[UIColor redColor]
                               range:NSMakeRange(9, amountString.length+1)];
            shifuText.attributedText = tempString;

        }

        return cell1;
        
    } else {
        
        if ([self.isXianhuo isEqualToString:@"订单详情"]) {
            
            MyorderDataList *gouwuMd=[[MyorderDataList alloc]initWith:self.OrderArray[indexPath.row]];
            
            //指定cellIdentifier为自定义的cell
            static NSString *CellIdentifier = @"huopinTBVCell";
            //自定义cell类有图片
            huopinTBVCell*cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            if (cell == nil) {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"huopinTBVCell" owner:self options:nil] lastObject];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
            }
            //顶部字符串拼接
            NSString *toplable;
            if ([TongYong isBlankObjectAndStr:gouwuMd.suface_code]) {
                toplable=[NSString stringWithFormat:@"%@ %@",gouwuMd.pro_category_name,gouwuMd.material_code];
            } else {
                toplable=[NSString stringWithFormat:@"%@ %@/%@",gouwuMd.pro_category_name,gouwuMd.material_code,gouwuMd.suface_code];
                
            }
            cell.topLabel.text=toplable;
            
            NSString *guige=gouwuMd.spec_code;
            
            //参厚
            NSString *canhou;
            if ([TongYong isBlankObjectAndStr:gouwuMd.reference_thick ]) {
                canhou=@"";
            } else {
                canhou=[NSString stringWithFormat:@"(%@)",gouwuMd.reference_thick];
            }
            
            //边部
            NSString *bianbu;
            if ([TongYong isBlankObjectAndStr:gouwuMd.edge_name ]) {
                bianbu=@"";
            } else {
                
                bianbu=[NSString stringWithFormat:@"/%@",gouwuMd.edge_name];
                
            }
            
            //等级
            NSString *dengji;
            if ([TongYong isBlankObjectAndStr:gouwuMd.level_name ]) {
                
                dengji=@"";
                
            } else {
                
                dengji=[NSString stringWithFormat:@"/%@",gouwuMd.level_name];
                
            }
        
            //包装
            NSString *baozhuang;
            if ([TongYong isBlankObjectAndStr:gouwuMd.package_type ]) {
                
                baozhuang=@"";
                
            } else {
                //包装类型//(30,"裸包"),(10,"简包"),(20,"精包"),(0,"正常包装")
                NSInteger typ=gouwuMd.package_type.integerValue;
                if (typ==30) {
                    baozhuang=[NSString stringWithFormat:@"/裸包"];
                } else if (typ==20) {
                    baozhuang=[NSString stringWithFormat:@"/精包"];
                } else if (typ==10) {
                    baozhuang=[NSString stringWithFormat:@"/简包"];
                } else {
                    
                    baozhuang=[NSString stringWithFormat:@"/正常包装"];
                }
            }
            
            //形状
            NSString *xinzhuang;
            if ([TongYong isBlankObjectAndStr:gouwuMd.shape ]) {
                
                xinzhuang=@"";
                
            } else {
                
                xinzhuang=[NSString stringWithFormat:@"/%@",gouwuMd.shape];
                
            }
            
            //品名
            NSString *pingming;
            if ([TongYong isBlankObjectAndStr:gouwuMd.category_name ]) {
                
                pingming=@"";
                
            } else {
                
                pingming=[NSString stringWithFormat:@"/%@",gouwuMd.category_name];
                
            }
            
            //单位类型
            NSInteger unitpric=gouwuMd.price_unit.integerValue;
            
            //并且计算出金额
            //计算金额
            //单位类型
            NSString *QUANTITY=[NSString stringWithFormat:@"%@",gouwuMd.quantity];
            NSString *weight=[NSString stringWithFormat:@"%@",gouwuMd.weight];
            NSString *sale_price=[NSString stringWithFormat:@"%@",gouwuMd.sale_price];
            
            NSDecimalNumber *quantityDM = [[NSDecimalNumber alloc] initWithString:QUANTITY];//个数
            NSDecimalNumber *weightDM = [[NSDecimalNumber alloc] initWithString:weight];//单个重量
            
            NSDecimalNumber *zongweightDM=[[NSDecimalNumber alloc]initWithString:@"0"];
            
            NSString *weightName;
            if (unitpric==10) {
                //元每吨
                NSDecimalNumber *qian = [[NSDecimalNumber alloc] initWithString:@"1000"];
                zongweightDM = [quantityDM decimalNumberByMultiplyingBy:weightDM];
                zongweightDM=[zongweightDM decimalNumberByDividingBy:qian];
                weightName=[NSString stringWithFormat:@"%@吨",[NSString notRounding:zongweightDM afterPoint:3]];
            } else if (unitpric==20||unitpric==40) {
                //支或张
                zongweightDM=quantityDM;
                weightName=[NSString stringWithFormat:@"%@",[NSString notRounding:zongweightDM afterPoint:0]];
            } else {
                //千克
                zongweightDM = [quantityDM decimalNumberByMultiplyingBy:weightDM];
                weightName=[NSString stringWithFormat:@"%@千克",[NSString notRounding:zongweightDM afterPoint:3]];
                
            }
            
            NSDecimalNumber *sale_priceDM = [[NSDecimalNumber alloc] initWithString:sale_price];
            NSDecimalNumber *everyON=[[NSDecimalNumber alloc]init];
            everyON = [sale_priceDM decimalNumberByMultiplyingBy:zongweightDM];

            cell.Moneylabel.text=[NSString stringWithFormat:@"￥%@元",[NSString notRounding:everyON afterPoint:2]];
            
            if (unitpric==20||unitpric==40) {
            
                zongweightDM = [quantityDM decimalNumberByMultiplyingBy:weightDM];
                weightName=[NSString stringWithFormat:@"%@千克",[NSString notRounding:zongweightDM afterPoint:3]];
            }
            
            NSString *bigTEXT;
            if ([gouwuMd.category_name isEqualToString:@"板"]||[gouwuMd.category_name isEqualToString:@"卷"]||[gouwuMd.category_name isEqualToString:@"带"]) {
                //		板卷   规格(参厚)/边部/等级/包装
                
                bigTEXT=[NSString stringWithFormat:@"%@%@%@%@/%@%@",guige,canhou,bianbu,dengji,weightName,baozhuang];
                
                
            } else {
                
                bigTEXT=[NSString stringWithFormat:@"%@%@%@%@/%@%@",guige,pingming,bianbu,dengji,weightName,baozhuang];
            }
            
            cell.bigLabel.text=bigTEXT;
            
            
            //仓库  生产商
            NSString *ck;
            if ([TongYong isBlankObjectAndStr:gouwuMd.house_name ]) {
                
                ck=@"";
                
            } else {
                
                ck=[NSString stringWithFormat:@"%@",gouwuMd.house_name];
                
            }
            
            NSString *scs;
            if ([TongYong isBlankObjectAndStr:gouwuMd.manufacturer_name ]) {
                
                scs=@"";
                
            } else {
                
                scs=[NSString stringWithFormat:@"%@",gouwuMd.manufacturer_name];
                
            }
            
            cell.dizhiandcangku.text=[NSString stringWithFormat:@"%@     %@",ck,scs];
            
            
            
            NSString *shulang=[NSString stringWithFormat:@"数量:x%@",gouwuMd.quantity];
            cell.Numlabel.text=shulang;
            
           

            return cell;

            
            
        }else{
        
         gouwucartModel *gouwuMd=[[gouwucartModel alloc]initWith:self.OrderArray[indexPath.row]];
        
            //指定cellIdentifier为自定义的cell
            static NSString *CellIdentifier = @"huopinTBVCell";
            //自定义cell类有图片
            huopinTBVCell*cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            if (cell == nil) {
                cell = [[[NSBundle mainBundle] loadNibNamed:@"huopinTBVCell" owner:self options:nil] lastObject];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
               
            }
                //顶部字符串拼接
                NSString *toplable;
                if ([TongYong isBlankObjectAndStr:gouwuMd.SURFACE_CODE]) {
                    toplable=[NSString stringWithFormat:@"%@ %@",gouwuMd.PARENT_NAME,gouwuMd.MATERIAL_CODE];
                } else {
                    toplable=[NSString stringWithFormat:@"%@ %@/%@",gouwuMd.PARENT_NAME,gouwuMd.MATERIAL_CODE,gouwuMd.SURFACE_CODE];
                    
                }
                cell.topLabel.text=toplable;
    
                //特惠图标
                NSInteger ispre=[gouwuMd.SALES_PROMOTION integerValue];
                if (ispre==2) {
                    cell.topTehuiImage.hidden=NO;
                    cell.topTehuiImage.image=[UIImage imageNamed:@"ic_preferential"];
                }else{
                    cell.topTehuiImage.hidden=YES;
                }

            
                NSString *guige=gouwuMd.SPEC_CODE;
                
                //参厚
                NSString *canhou;
                if ([TongYong isBlankObjectAndStr:gouwuMd.REFERENCE_THICK ]) {
                    canhou=@"";
                } else {
                    canhou=[NSString stringWithFormat:@"(%@)",gouwuMd.REFERENCE_THICK];
                }
                
                //边部
                NSString *bianbu;
                if ([TongYong isBlankObjectAndStr:gouwuMd.EDGE_NAME ]) {
                    bianbu=@"";
                } else {
                    
                    bianbu=[NSString stringWithFormat:@"/%@",gouwuMd.EDGE_NAME];
                    
                }
                
                //等级
                NSString *dengji;
                if ([TongYong isBlankObjectAndStr:gouwuMd.LEVEL_NAME ]) {
                    
                    dengji=@"";
                    
                } else {
                    
                    dengji=[NSString stringWithFormat:@"/%@",gouwuMd.LEVEL_NAME];
                    
                }
                
                
                //包装
                NSString *baozhuang;
                if ([TongYong isBlankObjectAndStr:gouwuMd.PACKAGE_TYPE ]) {
                    
                    baozhuang=@"";
                    
                } else {
                    //包装类型//(30,"裸包"),(10,"简包"),(20,"精包"),(0,"正常包装")
                    NSInteger typ=gouwuMd.PACKAGE_TYPE.integerValue;
                    if (typ==30) {
                        baozhuang=[NSString stringWithFormat:@"/裸包"];
                    } else if (typ==20) {
                        baozhuang=[NSString stringWithFormat:@"/精包"];
                    } else if (typ==10) {
                        baozhuang=[NSString stringWithFormat:@"/简包"];
                    } else {
                        
                        baozhuang=[NSString stringWithFormat:@"正常包装"];
                    }
                }
                
                
                //形状
                NSString *xinzhuang;
                if ([TongYong isBlankObjectAndStr:gouwuMd.SHAPE ]) {
                    
                    xinzhuang=@"";
                    
                } else {
                    
                    xinzhuang=[NSString stringWithFormat:@"/%@",gouwuMd.SHAPE];
                    
                }
                
                //品名
                NSString *pingming;
                if ([TongYong isBlankObjectAndStr:gouwuMd.CATEGORY_NAME ]) {
                    
                    pingming=@"";
                    
                } else {
                    
                    pingming=[NSString stringWithFormat:@"/%@",gouwuMd.CATEGORY_NAME];
                    
                }
            
            
            //单位类型
            NSInteger unitpric=gouwuMd.PRICE_UNIT.integerValue;
        
            //并且计算出金额
            //计算金额
            //单位类型
            NSString *QUANTITY=[NSString stringWithFormat:@"%@",gouwuMd.QUANTITY];
            NSString *weight=[NSString stringWithFormat:@"%@",gouwuMd.USEABLE_WEIGHT];
            NSString *sale_price=[NSString stringWithFormat:@"%@",gouwuMd.DISCOUNT_PRICE];
            
            NSDecimalNumber *quantityDM = [[NSDecimalNumber alloc] initWithString:QUANTITY];//个数
            NSDecimalNumber *weightDM = [[NSDecimalNumber alloc] initWithString:weight];//单个重量
            
            NSDecimalNumber *zongweightDM=[[NSDecimalNumber alloc]initWithString:@"0"];
            
             NSString *weightName;
            if (unitpric==10) {
                //元每吨
                NSDecimalNumber *qian = [[NSDecimalNumber alloc] initWithString:@"1000"];
                zongweightDM = [quantityDM decimalNumberByMultiplyingBy:weightDM];
                zongweightDM=[zongweightDM decimalNumberByDividingBy:qian];
                weightName=[NSString stringWithFormat:@"%@吨",[NSString notRounding:zongweightDM afterPoint:3]];
            } else if (unitpric==20||unitpric==40) {
                //支或张
                zongweightDM=quantityDM;
                weightName=[NSString stringWithFormat:@"%@",[NSString notRounding:zongweightDM afterPoint:0]];
            } else {
                //千克
                zongweightDM = [quantityDM decimalNumberByMultiplyingBy:weightDM];
                weightName=[NSString stringWithFormat:@"%@千克",[NSString notRounding:zongweightDM afterPoint:3]];
                
            }
            
            NSDecimalNumber *sale_priceDM = [[NSDecimalNumber alloc] initWithString:sale_price];
            NSDecimalNumber *everyON=[[NSDecimalNumber alloc]init];
            everyON = [sale_priceDM decimalNumberByMultiplyingBy:zongweightDM];
            
            
            cell.Moneylabel.text=[NSString stringWithFormat:@"￥%@元",[NSString notRounding:everyON afterPoint:2]];

            if (unitpric==20||unitpric==40) {
                
                zongweightDM = [quantityDM decimalNumberByMultiplyingBy:weightDM];
                weightName=[NSString stringWithFormat:@"%@千克",[NSString notRounding:zongweightDM afterPoint:3]];
            }
            
                NSString *bigTEXT;
                if ([gouwuMd.CATEGORY_NAME isEqualToString:@"板"]||[gouwuMd.CATEGORY_NAME isEqualToString:@"卷"]) {
                    //		板卷   规格(参厚)/边部/等级/包装
                    
                    bigTEXT=[NSString stringWithFormat:@"%@%@%@%@/%@%@",guige,canhou,bianbu,dengji,weightName,baozhuang];
                    
                    
                } else {
                    
                    bigTEXT=[NSString stringWithFormat:@"%@%@%@%@%@/%@%@",guige,pingming,xinzhuang,bianbu,dengji,weightName,baozhuang];
                }
                
                cell.bigLabel.text=bigTEXT;
                
                
                //仓库  生产商
                NSString *ck;
                if ([TongYong isBlankObjectAndStr:gouwuMd.HOUSE_NAME ]) {
                    
                    ck=@"";
                    
                } else {
                    
                    ck=[NSString stringWithFormat:@"%@",gouwuMd.HOUSE_NAME];
                    
                }
                
                NSString *scs;
                if ([TongYong isBlankObjectAndStr:gouwuMd.MANUFACTURER_NAME ]) {
                    
                    scs=@"";
                    
                } else {
                    
                    scs=[NSString stringWithFormat:@"%@",gouwuMd.MANUFACTURER_NAME];
                    
                }
                
                cell.dizhiandcangku.text=[NSString stringWithFormat:@"%@     %@",ck,scs];
            
                NSString *shulang=[NSString stringWithFormat:@"数量:x%@",gouwuMd.QUANTITY];
                cell.Numlabel.text=shulang;
                
            
            return cell;
        
    }

}
    
}
    
}

//选中单元格时执行的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //    // 取消选中状态
    //    [tableView deselectRowAtIndexPath:indexPath animated:NO];

    
}

- (void)backLogin {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
